module FacebookHelper
  
  def facebook_base_url
     "http://graph.facebook.com/"
  end
  def facebook_app_url
    "http://apps.facebook.com/"+WEBAPP_CONFIG['facebook_canvas']
  end
  def fb_user_picture(uid, type=:square)
    
    image_tag(facebook_base_url+uid.to_s+"/picture?type=#{type}", :border=>0)  
  end
  
  def do_fb_authentication
    html = ""
    if !fb_user
      html +="<script>"
      html +="window.top.location.href=\"#{new_oauth_url}\""
      html +="</script>"
    end
    html
  end
  
  
  
  def facebook_javascripts  
    js_code = "";
    js_code +=javascript_include_tag("http://connect.facebook.net/en_US/all.js");
  end
  
  def facebook_connect_button
    html_code = "<fb:login-button v=\"2\"><fb:intl>Connect with Facebook</fb:intl></fb:login-button>"
  end
  
  
  def facebook_api_init
    
    
    js_code = "<div id='fb-root'><div>"
    js_code +="<script>"
    js_code += "window.fbAsyncInit = function() {FB.init({appId: '#{WEBAPP_CONFIG["facebook_client_id"]}', status: true, cookie: true,xfbml: true});FB.Canvas.setAutoResize();};"
    js_code += "(function() {var e = document.createElement('script'); e.async = true;"
    js_code +="e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js';"
    js_code +="document.getElementById('fb-root').appendChild(e);}());"
    #js_code += "window.alert(FB.getSession());"
    #js_code +="window.fbAsyncInit = function() {FB.Canvas.setAutoResize();}"
    js_code +="</script>"  
  end   
end
